import Vue from 'vue'
import { getAll } from '@/api/daEquipment'

export default class Equipment {
  constructor(equipment) {
    this.equipment = equipment
  }
  async init() {
    const ps = []
    Vue.set(this.equipment.equipment, 'da_equipment', {})
    Vue.set(this.equipment.label, 'da_equipment', {})
    Vue.set(this.equipment, 'da_equipment', [])
    ps.push(getAll().then(data => {
      this.equipment['da_equipment'].splice(0, 0, ...data.content)
      data.content.forEach(d => {
        Vue.set(this.equipment.equipment['da_equipment'], d.id, d)
        Vue.set(this.equipment.label['da_equipment'], d.id, d.serialnumber)
      })
    }))
    await Promise.all(ps)
  }
}
